/******************************************************************************
 *                  Shanghai ChipON Micro-Electronic Co.,Ltd                  *
 ******************************************************************************
 *  $File Name$       : main.c                                         	      *
 *  $Author$          : ChipON AE/FAE Group                                   *
 *  $Data$            : 2021-12-20                                            *
 *  $AutoSAR Version  : V1.0	                                              *
 *  $Description$     : This is a template project used by general timer.	  *
 ******************************************************************************
 *  Copyright (C) by Shanghai ChipON Micro-Electronic Co.,Ltd                 *
 *  All rights reserved.                                                      *
 *                                                                            *
 *  This software is copyrght protected and proprietary to                    *
 *  Shanghai ChipON Micro-Electronic Co.,Ltd.                                 *
 ******************************************************************************
 *  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  *
 *                     		REVISON HISTORY                               	  *
 *  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  *
 *  Data       Version  Author        Description                             *
 *  ~~~~~~~~~~ ~~~~~~~~ ~~~~~~~~~~~~  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  *
 *  2021-12-20 00.01.00 FAE Group     new creat                               *
 *                                                                            *
 *                                                                            *
 *****************************************************************************/

/******************************************************************************
**                      		Include Files                                **
******************************************************************************/
#include "system_init.h"
#include "User_T18.h"
#include "Usart.h"


/* Private variables *********************************************************/
static uint16_t Counter=0;
static uint8_t Counter_buf[2]={0};

/* public variables ***********************************************************/

/*******************************************************************************
**                     			main Functions 		             	     	  **
*******************************************************************************/
int main()
{
	/*initialize system clock,defaut SCLK is 72M,select INTHF as Clock source*/
	SystemInit(72);
	GPIO_Write_Mode_Bits(GPIOF_SFR,GPIO_PIN_MASK_11,GPIO_MODE_OUT);
	
	/*set PA2 as the T18 conuter input pin************************************/
	GPIO_Write_Mode_Bits(GPIOA_SFR,GPIO_PIN_MASK_0,GPIO_MODE_RMP);
	GPIO_Pin_RMP_Config(GPIOA_SFR,GPIO_PIN_MASK_0,GPIO_RMP_AF2);
	/*Initialize Timer 18 and configuration Timer 18 interrupt****************
	Select 1/(15+1) HFCLK as clock source,Counting period is 5000, every 5ms
	enter once T18 Interrupt*************************************************/
	GENERAL_TIMER18_Config(5000,15);
	
	UsartGpioInit();
	USART_Async_config(USART0_SFR);
	while(1)
	{
		Counter=T18_CNT;
		Counter_buf[0]=Counter&0xff;
		Counter_buf[1]=Counter>>8;
		USART_Send(USART0_SFR,Counter_buf,2);
	}		
}
/**
 *  @brief : Reports the name of the source file and the source line number
 *           where the assert_param error has occurred.
 *  @param in :	file pointer to the source file name
 * 	@param in :	line assert_param error line source number
 *  @param out :None
 *  @retval :None
 */
void check_failed(uint8_t* File, uint32_t Line)
{
	/* User can add his own implementation to report the file name and line number,
		ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

	/* Infinite loop */
	while(1)
	{
		;
	}
};
